package com.wolf.cx330.view.frag

import android.animation.ObjectAnimator
import android.animation.TypeEvaluator
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.wolf.cx330.R
import kotlinx.android.synthetic.main.frag_text_anim.*

class TextAnimFrag : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View = inflater.inflate(R.layout.frag_text_anim, container, false)

    private val list = mutableListOf(
        "北京市",
        "天津市",
        "上海市",
        "重庆市",
        "河北省",
        "山西省",
        "辽宁省",
        "吉林省",
        "黑龙江省",
        "江苏省",
        "浙江省",
        "安徽省",
        "福建省",
        "江西省",
        "山东省",
        "河南省",
        "湖北省",
        "湖南省",
        "广东省",
        "海南省",
        "四川省",
        "贵州省",
        "云南省",
        "陕西省",
        "甘肃省",
        "青海省",
        "台湾省",
        "内蒙古自治区",
        "广西壮族自治区",
        "西藏自治区",
        "宁夏回族自治区",
        "新疆维吾尔自治区",
        "香港特别行政区",
        "澳门特别行政区"
    )

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        val anim = ObjectAnimator.ofObject(
            ftaTextAnimView, "textVal",
            TypeEvaluator<String> { fraction, startValue, endValue ->
                val startIndex = list.indexOf(startValue)
                val endIndex = list.indexOf(endValue)
                val resultIndex = (startIndex + (endIndex - startIndex) * fraction).toInt()
                val result = list[resultIndex]
                println("【IM】TextAnimFrag  onActivityCreated: $result")
                result
            }, "澳门特别行政区"
        )
        anim.apply {
            duration = 5000
            startDelay = 1000
            start()
        }
    }
}